package org.pgis.entity;

import java.awt.Color;

import vtk.vtkActor;

public class ConnectingLine {

	private Color lineColor = Color.green;
	private Point3d startPoint;
	private Point3d endPoint;
	private vtkActor startActor;
	private vtkActor endActor;

	public ConnectingLine() {
		super();
	}

	public ConnectingLine(Point3d startPoint, Point3d endPoint) {
		super();
		this.startPoint = startPoint;
		this.endPoint = endPoint;
	}

	public ConnectingLine(vtkActor start, vtkActor end ) {
		startPoint = new Point3d(start.GetPosition()[0], start.GetPosition()[1], start.GetPosition()[2]);
		endPoint = new Point3d(end.GetPosition()[0], end.GetPosition()[1], end.GetPosition()[2]);
	}

	public double getDistance() {
		return Math.sqrt(	Math.pow((startPoint.getX() - endPoint.getX()), 2) +
							Math.pow((startPoint.getY() - endPoint.getY()), 2) +
							Math.pow((startPoint.getZ() - endPoint.getZ()), 2));
	}

	public Point3d getStartPoint() {
		return startPoint;
	}

	public void setStartPoint(Point3d startPoint) {
		this.startPoint = startPoint;
	}

	public Point3d getEndPoint() {
		return endPoint;
	}

	public void setEndPoint(Point3d endPoint) {
		this.endPoint = endPoint;
	}

	public vtkActor getStartActor() {
		return startActor;
	}

	public void setStartActor(vtkActor startActor) {
		this.startActor = startActor;
	}

	public vtkActor getEndActor() {
		return endActor;
	}

	public void setEndActor(vtkActor endActor) {
		this.endActor = endActor;
	}

	public Color getLineColor() {
		return lineColor;
	}

	public void setLineColor(Color lineColor) {
		this.lineColor = lineColor;
	}

	public String toString() {
		return "Start Point \n\t" + startPoint + "\n End Point : \n\t" + endPoint + " \n Distance : \t " + getDistance();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((endActor == null) ? 0 : endActor.hashCode());
		result = prime * result
				+ ((endPoint == null) ? 0 : endPoint.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ConnectingLine other = (ConnectingLine) obj;
		if (endActor == null) {
			if (other.endActor != null)
				return false;
		} else if (!endActor.equals(other.endActor))
			return false;
		if (endPoint == null) {
			if (other.endPoint != null)
				return false;
		} else if (!endPoint.equals(other.endPoint))
			return false;
		return true;
	}

}
